//
//  BUIView.m
//  sample
//
//  Created by 张玺 on 12-9-10.
//  Copyright (c) 2012年 张玺. All rights reserved.
//

#import "BNSObject.h"
#import <objc/runtime.h>

@implementation NSObject(BNSObject)

+(void)perform:(void(^)())block1 withCompletionHandler:(void (^)())block2
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        block1();
        dispatch_async(dispatch_get_main_queue(),^{
            block2();
        });
    }); 
}
-(void)perform:(void(^)())block1 withCompletionHandler:(void (^)())block2
{
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        block1();
        dispatch_async(dispatch_get_main_queue(),^{
            block2();
        });
    });
}
-(void)perform:(void(^)())block1 inQueue:(dispatch_queue_t)customQueue withCompletionHandler:(void (^)())block2
{
    dispatch_async(customQueue, ^{
        block1();
        dispatch_async(dispatch_get_main_queue(),^{
            block2();
        });
    });
   /* dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        
        dispatch_async(customQueue, ^{
            block1();
            dispatch_async(dispatch_get_main_queue(),^{
                block2();
            });
        });
        
       
    });*/
}
//added by yangmin
-(void)performBlock:(void (^)())block afterDelay:(NSTimeInterval)time{
    dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, time * NSEC_PER_SEC);
    dispatch_after(popTime, dispatch_get_main_queue(), ^(void){
        @autoreleasepool {
            block();
        }
    });
}
@end
